﻿var map = null;
function CreateMap() {
    // 创建地图实例
    map = new BMap.Map("container");
    // 创建点坐标
    var point = new BMap.Point(116.404, 39.915);
    // 初始化地图，设置中心点坐标和地图级别
    map.centerAndZoom(point, 15);
}

function CenterToPoint(x, y) {
    var point = new BMap.Point(x, y);
    map.centerAndZoom(point, 15);
}

function DrawLine(data) {
    var polyline = new BMap.Polyline(
            { strokeColor: "red", strokeWeight: 1, strokeOpacity: 0.5 }
    );
    var linelist = new Array();
    for (var i = 0; i < data.length; i++) {
        var point = new BMap.Point(data[i][0], data[i][1]);
        linelist.push(point);
        if (i == 0) {
            AddStartMarker(point);
        }
        else if (i == data.length - 1) {
            AddEndMarker(point);
        }
        else {
            var marker = new BMap.Marker(point);
            map.addOverlay(marker);
        }
    }
    polyline.setPath(linelist);
    map.addOverlay(polyline);
}

function AddMark(x,y) {
    var point = new BMap.Point(x, y);
    map.centerAndZoom(point, 15);
    // 创建标注
    var marker = new BMap.Marker(point);
    map.addOverlay(marker);
}

function CallMethod() {
    JSMethod.run();
}

function AddStartMarker(point) {
    var myIcon = new BMap.Icon("./Content/icon_nav_start_l.png", new BMap.Size(23, 25));
    var marker = new BMap.Marker(point, { icon: myIcon });
    map.addOverlay(marker);
}

function AddEndMarker(point) {
    var myIcon = new BMap.Icon("./Content/icon_nav_end_l.png", new BMap.Size(23, 25));
    var marker = new BMap.Marker(point, { icon: myIcon });
    map.addOverlay(marker);
}

